package com.water.control.adapter;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.water.control.R;
import com.water.control.bean.WaterLevelEntity;

import java.util.List;

public class OnlineLevelAdapter extends BaseAdapter {

    Context context;
    List<WaterLevelEntity> entities;
    LayoutInflater inflater;

    public OnlineLevelAdapter(Context context, List<WaterLevelEntity> entities) {
        this.context = context;
        inflater = LayoutInflater.from(context);
        this.entities = entities;
    }

    @Override
    public int getCount() {
        return entities.size();
    }

    @Override
    public Object getItem(int position) {
        return entities.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewGroup vg;

        if (convertView != null) {
            vg = (ViewGroup) convertView;
        } else {
            vg = (ViewGroup) inflater.inflate(R.layout.item_level, null);
        }

        WaterLevelEntity entity = entities.get(position);

        /*******时间********/
        TextView tvTime = vg.findViewById(R.id.time);
        tvTime.setText("接收：" + entity.getTime() + "");

        /*******心率值********/
        TextView tvRate = vg.findViewById(R.id.level);
        tvRate.setText(entity.getLevel() + "");

        return vg;
    }

}
